package antoine.ear.generator;

import java.util.List;

import javax.sound.midi.MetaMessage;
import javax.sound.midi.MidiEvent;
import javax.sound.midi.ShortMessage;

import antoine.ear.generator.sequences.Alt7SequenceGenerator;

public abstract class ChordGenerator {
	
	private static final int	VELOCITY = 64;
	public int tonique;
	public SequenceGenerator sequenceGenerator;
	
	public abstract List generate(int note, int tick, int delay);
	public abstract String chordName();
	public abstract void reinit();

	protected MidiEvent createNoteOffEvent(int nKey, long lTick){
		return createNoteEvent(ShortMessage.NOTE_OFF, nKey,  0, lTick);
	}
	
	protected MidiEvent createNoteOnEvent(int nKey, long lTick) {
		return createNoteEvent(ShortMessage.NOTE_ON, nKey, VELOCITY, lTick);
	}

	protected MidiEvent createNoteEvent(int nCommand, int nKey, int nVelocity, long lTick)	{
		ShortMessage message = new ShortMessage();
		try	{
			message.setMessage(nCommand, 0,	 nKey, nVelocity);
		}
		catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		}
		MidiEvent event = new MidiEvent(message,  lTick);
		return event;
	}
	
	protected MidiEvent createMetaMessOnEvent(int nKey, long lTick, int type)	{
		MetaMessage	message = new MetaMessage();
		try	{
			byte[] tab = new byte[1];
			tab[0] = (byte) nKey;
			message.setMessage(type, tab,	1);
		}
		catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		}
		MidiEvent event = new MidiEvent(message,  lTick);
		return event;
	}
}
